package cn.bugstack.mybatis.scripting.defaults;

import cn.bugstack.mybatis.builder.SqlSourceBuilder;
import cn.bugstack.mybatis.mapping.BoundSql;
import cn.bugstack.mybatis.mapping.SqlSource;
import cn.bugstack.mybatis.scripting.xmltags.DynamicContext;
import cn.bugstack.mybatis.scripting.xmltags.MixedSqlNode;
import cn.bugstack.mybatis.session.Configuration;

public class RawSqlSource implements SqlSource {

    private SqlSource sqlSource;

    public RawSqlSource(SqlSource sqlSource) {
        this.sqlSource = sqlSource;
    }

    public RawSqlSource(Configuration configuration, MixedSqlNode rootSqlNode, Class<?> parameterType) {


        DynamicContext dynamicContext = new DynamicContext(configuration, null);
        rootSqlNode.apply(dynamicContext);

        SqlSourceBuilder sqlSourceBuilder = new SqlSourceBuilder(configuration);
        sqlSource = sqlSourceBuilder.parse(dynamicContext.getSql(), parameterType);
    }

    @Override
    public BoundSql getBoundSql(Object parameterObject) {
        return sqlSource.getBoundSql(parameterObject);
    }


}
